import {Injectable} from '@angular/core';
import {Response} from '@angular/http';
import {HttpService} from '@core/http/http.service';
import {BehaviorSubject} from 'rxjs';
import * as API from "@api/index";
@Injectable()
export class ShareService {

  public _liveBroadcast: BehaviorSubject<any> = new BehaviorSubject<any>({});

  constructor(private httpSer: HttpService) {
  }

  get liveBroadcast() {
    return this._liveBroadcast.asObservable();
  }

  getLiveBroadcast(liveId: string) {
    const url = API.LIVE_BROADCAST + `?liveId=${liveId}`;
    this.httpSer
      .get(url)
      .map((res: Response) => res.json())
      .subscribe(res => {
        this._liveBroadcast.next(res);
      });
  }

  getVideo(videoId: string) {
    const url = API.VIDEO_DETAIL + `?videoId=${videoId}`;
    this.httpSer
      .get(url)
      .map((res: Response) => res.json())
      .subscribe(res => {
        this._liveBroadcast.next(res);
      });
  }

   // 查询组织中心信息
  getGroupInfo(group_id) {
    const url = API.GROUP_CENTER + '?groupId=' + group_id;
    return this.httpSer.get(url).map(res => res.json());
  }

   // 查询组织成员列表
  getGroupMemberList(group_id) {
    const url = API.GROUP_MERBERLIST + '?groupId=' + group_id;
    return this.httpSer.get(url).map(res => res.json());
  }
}
